package com.example.bootintegration;

import com.example.bootintegration.asyn.AsyncTaskExecutionListener;
import com.example.bootintegration.entity.User;
import com.example.bootintegration.webtest.WebMvcConfig;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Scope;

import java.util.Collection;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebMvcConfig.class)})
//@EnableAspectJAutoProxy      AopAutoConfiguration 中会自动注册

// @EnableRetry
// @EnableScheduling
// @EnableJpaAuditing
public class BootIntegrationApplication {


    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(BootIntegrationApplication.class);
        // BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2048);
        // applicationStartup.startRecording();
        // springApplication.setApplicationStartup(applicationStartup);
        springApplication.run(args);

        // ConfigurableApplicationContext run = SpringApplication.run(BootIntegrationApplication.class, args);
        // User bean = run.getBean("test2", User.class);
        // bean = run.getBean("test2", User.class);
        // bean = run.getBean("test2", User.class);
        // System.out.println(bean);
        //
        // ServerEndpointExporter bean1 = run.getBean(ServerEndpointExporter.class);
        // System.out.println(bean1);
    }

    @Autowired
    void testProvicer(ObjectProvider<Collection<User>> cacheProvider) {
        cacheProvider.getIfAvailable().forEach(System.out::println);
        System.out.println("configurers = " + cacheProvider);
    }


    @Bean(initMethod = "init")
    public User test() {

        return new User();
    }

    @Bean(initMethod = "init")
    @Scope(value = "prototype")
    public User test2() {

        return new User();
    }

    @Bean
    public AsyncTaskExecutionListener asyncTaskExecutionListener() {
        return new AsyncTaskExecutionListener();
    }


}
